<template>
  <div class="block">
    <span class="demonstration" />
    <el-cascader
      :value="value"
      size="mini"
      :props="props"
      :options="treeData"
      separator="-"
      @change="changeValue"
    />
  </div>
</template>

<script>
// 映入之前封装的部门请求
import { getDpartment } from '@/api/department'
// 引入之前封装的树形
import { translateListToTree } from '@/utils'
export default {
  props: {
    value: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      treeData: [],
      props: {
        value: 'id', // 要存储的内容(文档需要的部门请求传递的部门id）
        label: 'name'// 要显示的内容
      }
    }
  },
  created() {
    this.getDpartment()
  },
  methods: {
    async getDpartment() {
      this.treeData = translateListToTree(await getDpartment(), 0)
    },
    changeValue(list) {
      if (list.length > 0) {
        this.$emit('input', list[list.length - 1])
      } else {
        this.$emit('input', null)
      }
    }
  }

}
</script>

<style>

</style>
